package cn.wolfcode.wolf2w.spot.controller.admin;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import cn.wolfcode.wolf2w.common.core.domain.R;
import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.wolfcode.wolf2w.spot.query.SpotContextQuery;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wolfcode.wolf2w.common.log.annotation.Log;
import cn.wolfcode.wolf2w.common.log.enums.BusinessType;
import cn.wolfcode.wolf2w.common.security.annotation.RequiresPermissions;
import cn.wolfcode.wolf2w.spot.api.domain.SpotContext;
import cn.wolfcode.wolf2w.spot.service.ISpotContextService;
import cn.wolfcode.wolf2w.common.core.web.controller.BaseController;
import cn.wolfcode.wolf2w.common.core.utils.poi.ExcelUtil;


/**
 * 景点内容Controller
 * 
 * @author dalang
 * @date 2023-11-23
 */
@RestController
@RequestMapping("/admin/spotContexts")
public class SpotContextAdminController extends BaseController
{
    @Autowired
    private ISpotContextService spotContextService;

    /**
     * 查询景点内容列表
     */
    @RequiresPermissions("spot:spotContext:list")
    @GetMapping("/list")
    public R<IPage<SpotContext>> list(SpotContextQuery qo) {
        return R.ok(spotContextService.queryPage(qo));
    }


    /**
     * 导出景点内容列表
     */
    @RequiresPermissions("spot:spotContext:export")
    @Log(title = "景点内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpotContext spotContext)
    {
        List<SpotContext> list = spotContextService.list();
        ExcelUtil<SpotContext> util = new ExcelUtil<SpotContext>(SpotContext.class);
        util.exportExcel(response, list, "景点内容数据");
    }

    /**
     * 获取景点内容详细信息
     */
    @RequiresPermissions("spot:spotContext:query")
    @GetMapping(value = "/{id}")
    public R<SpotContext> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(spotContextService.getById(id));
    }

    /**
     * 新增景点内容
     */
    @RequiresPermissions("spot:spotContext:add")
    @Log(title = "景点内容", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody SpotContext spotContext)
    {
        return toAjax(spotContextService.save(spotContext));
    }

    /**
     * 修改景点内容
     */
    @RequiresPermissions("spot:spotContext:edit")
    @Log(title = "景点内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody SpotContext spotContext)
    {
        return toAjax(spotContextService.updateById(spotContext));
    }

    /**
     * 删除景点内容
     */
    @RequiresPermissions("spot:spotContext:remove")
    @Log(title = "景点内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<?> remove(@PathVariable Long[] ids)
    {
        return toAjax(spotContextService.removeByIds(Arrays.stream(ids).collect(Collectors.toList())));
    }
}
